package com.ljx.controller;

import com.ljx.common.ResponseResult;
import com.ljx.domain.dto.UserDto;
import com.ljx.domain.entity.User;
import com.ljx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李捷禧
 * Date: 2023/4/22
 * ClassName: UserController
 */
@RestController
@RequestMapping("system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize,String userName,String phonenumber,String status){
        return userService.listAll(pageNum,pageSize,userName,phonenumber,status);
    }

    @PostMapping
    public ResponseResult add(@RequestBody UserDto user){
        userService.saveUser(user);
        return ResponseResult.okResult("添加成功");
    }

    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable List<Long> id){
        userService.removeByIds(id);
        return ResponseResult.okResult("删除成功");
    }

    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Long id){
      return userService.getUserOne(id);
    }

    @PutMapping
    public ResponseResult update(@RequestBody UserDto user){
        userService.updateUserById(user);
        return ResponseResult.okResult("修改成功");
    }


}
